package cn.one.controller;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * 需要在springmvc-servlet加载资源映射
 * <mvc:resources location="classpath:/META-INF/resources/" mapping="swagger-ui.html"></mvc:resources>
 * <mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"></mvc:resources>
 *版本冲突,不兼容,
 * com.alibaba|fastjson|1.2.31,兼容springfox-swagger2|2.4.0和springfox-swagger-ui|2.4.0
 *      不兼容springfox-swagger2|2.8.0和springfox-swagger-ui|2.8.0
 *需要修改TomcatServer的路径-
 *     -open browser不能加项目名 http://localhost:8880/
 *     否侧冲突无限报页面循环
 * 不能有相同的 value  @Api(value = "API")
 * 			   value  @ApiOperation(value ="通过id获取USER".....
 *
 */
//@EnableWebMvc
@EnableSwagger2//启用swagger
@ComponentScan(basePackages = {"cn.one.controller"})//设置扫描controller包
@Configuration//自动加载环境配置
public class SwaggerConfig extends WebMvcConfigurationSupport {

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors.any())
				.paths(PathSelectors.any())
				.build();
		//select控制API接口的开发
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("one-主业务模块API")
				.termsOfServiceUrl("localhost:8880/biz/")
				.contact("one项目组")
				.version("1.0")
				.build();
	}
}